<?php
class ORMMyOrder extends ORMBase {
  public function __construct() {
    parent::__construct('MyOrder');
  }

  public function __toEpObject($myManager, $epObject, $object) {
    require_once dirname(__FILE__) . '/ORMOrderEvent.class.php';
    require_once dirname(__FILE__) . '/ORMOrderPackage.class.php';
    require_once dirname(__FILE__) . '/ORMOrderProduce.class.php';
    require_once dirname(__FILE__) . '/ORMOrderPurchase.class.php';
    require_once dirname(__FILE__) . '/ORMOrderTask.class.php';
    require_once dirname(__FILE__) . '/ORMStatus.class.php';
    require_once dirname(__FILE__) . '/ORMUser.class.php';
    $epObject->trackId = isset($object->trackId) ? $object->trackId : '';
    $epObject->createdDate = isset($object->createdDate) ? SimpleDate::toStamp($object->createdDate) : 0;
    $epObject->cancelled = isset($object->cancelled) ? $object->cancelled : 0;
    $epObject->type = isset($object->type) ? $object->type : '';
    $epObject->price = isset($object->price) ? $object->price : 0;
    if (isset($object->photo) && $object->photo) {
        $epObject->photo = $this->__getEpObject_4_lvl_1_object($myManager, $object->photo, new ORMOrderPackage(), 'OrderPackage');
    } else {
      if (isset($epObject->photo)) {
        $my_manager->delete($epObject->photo);
      }
    }
    if (isset($object->video) && $object->video) {
        $epObject->video = $this->__getEpObject_4_lvl_1_object($myManager, $object->video, new ORMOrderPackage(), 'OrderPackage');
    } else {
      if (isset($epObject->video)) {
        $my_manager->delete($epObject->video);
      }
    }
    $epObject->note = isset($object->note) ? $object->note : '';
    if (isset($epObject->purchases)) {
      $epObject->purchases->removeAll();
      foreach ($object->purchases as &$item) {
        $epObject->purchases[] = $this->__getEpObject_4_lvl_1_object($myManager, $item, new ORMOrderPurchase(), 'OrderPurchase');
      }
    }
    if (isset($epObject->produces)) {
      $epObject->produces->removeAll();
      foreach ($object->produces as &$item) {
        $epObject->produces[] = $this->__getEpObject_4_lvl_1_object($myManager, $item, new ORMOrderProduce(), 'OrderProduce');
      }
    }
    if (isset($epObject->tasks)) {
      $epObject->tasks->removeAll();
      foreach ($object->tasks as &$item) {
        $epObject->tasks[] = $this->__getEpObject_4_lvl_1_object($myManager, $item, new ORMOrderTask(), 'OrderTask');
      }
    }
    if (isset($epObject->events)) {
      $epObject->events->removeAll();
      foreach ($object->events as &$item) {
        $epObject->events[] = $this->__getEpObject_4_lvl_1_object($myManager, $item, new ORMOrderEvent(), 'OrderEvent');
      }
    }
    if (isset($object->who) && $object->who) {
        $epObject->who = $this->__getEpObject_4_lvl_1_object($myManager, $object->who, new ORMUser(), 'User');
    } else {
      if (isset($epObject->who)) {
        $my_manager->delete($epObject->who);
      }
    }
    $epObject->when = isset($object->when) ? SimpleDate::toStamp($object->when) : 0;
    if (isset($object->music) && $object->music) {
        $epObject->music = $this->__getEpObject_4_lvl_1_object($myManager, $object->music, new ORMStatus(), 'Status');
    } else {
      if (isset($epObject->music)) {
        $my_manager->delete($epObject->music);
      }
    }
    if (isset($object->precon) && $object->precon) {
        $epObject->precon = $this->__getEpObject_4_lvl_1_object($myManager, $object->precon, new ORMStatus(), 'Status');
    } else {
      if (isset($epObject->precon)) {
        $my_manager->delete($epObject->precon);
      }
    }
    return $epObject;
  }

  public function __toObject($myManager, $epObject, $object) {
    require_once dirname(__FILE__) . '/ORMOrderEvent.class.php';
    require_once dirname(__FILE__) . '/ORMOrderPackage.class.php';
    require_once dirname(__FILE__) . '/ORMOrderProduce.class.php';
    require_once dirname(__FILE__) . '/ORMOrderPurchase.class.php';
    require_once dirname(__FILE__) . '/ORMOrderTask.class.php';
    require_once dirname(__FILE__) . '/ORMStatus.class.php';
    require_once dirname(__FILE__) . '/ORMUser.class.php';
    $object->id = $epObject->oid;
    $object->trackId = $epObject->trackId;
    $object->createdDate = SimpleDate::fromStamp($epObject->createdDate);
    $object->cancelled = $epObject->cancelled;
    $object->type = $epObject->type;
    $object->price = $epObject->price;
    if (isset($epObject->photo)) {
      $object->photo = $this->__getObject_4_lvl_1_ep_object($myManager, $epObject->photo, new ORMOrderPackage());
    }
    if (isset($epObject->video)) {
      $object->video = $this->__getObject_4_lvl_1_ep_object($myManager, $epObject->video, new ORMOrderPackage());
    }
    $object->note = $epObject->note;
    $object->purchases = array();
    if (isset($epObject->purchases)) {
      foreach ($epObject->purchases as &$item) {
        $object->purchases[] = $this->__getObject_4_lvl_1_ep_object($myManager, $item, new ORMOrderPurchase());
      }
    }
    $object->produces = array();
    if (isset($epObject->produces)) {
      foreach ($epObject->produces as &$item) {
        $object->produces[] = $this->__getObject_4_lvl_1_ep_object($myManager, $item, new ORMOrderProduce());
      }
    }
    $object->tasks = array();
    if (isset($epObject->tasks)) {
      foreach ($epObject->tasks as &$item) {
        $object->tasks[] = $this->__getObject_4_lvl_1_ep_object($myManager, $item, new ORMOrderTask());
      }
    }
    $object->events = array();
    if (isset($epObject->events)) {
      foreach ($epObject->events as &$item) {
        $object->events[] = $this->__getObject_4_lvl_1_ep_object($myManager, $item, new ORMOrderEvent());
      }
    }
    if (isset($epObject->who)) {
      $object->who = $this->__getObject_4_lvl_1_ep_object($myManager, $epObject->who, new ORMUser());
    }
    $object->when = SimpleDate::fromStamp($epObject->when);
    if (isset($epObject->music)) {
      $object->music = $this->__getObject_4_lvl_1_ep_object($myManager, $epObject->music, new ORMStatus());
    }
    if (isset($epObject->precon)) {
      $object->precon = $this->__getObject_4_lvl_1_ep_object($myManager, $epObject->precon, new ORMStatus());
    }
    return $object;
  }
}
?>
